import { Repository, In } from 'typeorm';
import { InjectRepository } from '@nestjs/typeorm';
import { TBlogUser } from 'src/entities/blog/user.entity';
// import { UserRegisterDto } from './dto/user-register.dto';

export class UserRepository {
  constructor(
    @InjectRepository(TBlogUser)
    private readonly userRepository: Repository<TBlogUser>,
  ) {}

  // 获取指定账号的用户
  findOneRepository(data: { account: string }) {
    return this.userRepository.findOne({
      where: { account: data.account },
    });
  }

  // 获取指定账号的用户
  findRepository(data: { ids: number[] }) {
    return this.userRepository.find({
      // @ts-ignore
      id: In(data.ids),
    });
  }

  // 添加一条数据信息
  addOneRepository(data: TBlogUser) {
    return this.userRepository.save(data);
  }

  // 注册
  registerRepository(data: TBlogUser) {
    return this.userRepository.save(data);
  }

  // 登录
  loginRepository(data: { account: string }) {
    return this.userRepository.findOne({
      where: { account: data.account },
    });
  }
}
